package jatosoft.accounting.dao.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
public class VoucherItem extends BaseModel implements Serializable{
	private static final long serialVersionUID = 8858277107715992452L;
	private Integer seq;
	private String item;
	private Account account;
	private Double amount = 0.0;
	private Voucher voucher;

	public VoucherItem(Account a) {
		this.account=a;
	}

	public VoucherItem() {
	}

	@ManyToOne()
	@JoinColumn(name="VOUCHER_ID")
	public Voucher getVoucher() {
		return voucher;
	}

	public void setVoucher(Voucher voucher) {
		this.voucher = voucher;
	}

	public Integer getSeq() {
		return seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	public String getItem() {
		return item;
	}

	public void setItem(String item) {
		this.item = item;
	}

	@ManyToOne
	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	@Id
	@Column(name = "VOUCHER_ITEM_ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("VoucherItem [account=");
		builder.append(account);
		builder.append(", amount=");
		builder.append(amount);
		builder.append(", id=");
		builder.append(id);
		builder.append(", item=");
		builder.append(item);
		builder.append(", seq=");
		builder.append(seq);
		builder.append("]");
		return builder.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((seq == null) ? 0 : seq.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		VoucherItem other = (VoucherItem) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (seq == null) {
			if (other.seq != null)
				return false;
		} else if (!seq.equals(other.seq))
			return false;
		return true;
	}


	public VoucherItem clone() {
		VoucherItem vi = new VoucherItem();
		vi.setId(id);
		vi.setAccount(account);
		vi.setAmount(amount);
		vi.setItem(item);
		vi.setSeq(seq);
		return vi;
	}

	public int compareTo(Voucher o) {
		// TODO Auto-generated method stub
		return 0;
	}

	public VoucherItem copy() {
		VoucherItem vi = new VoucherItem();
		vi.setAccount(account);
		vi.setAmount(amount);
		vi.setItem(item);
		vi.setSeq(seq);
		return vi;
	}
}
